package com.situ.mall.user.controller;


import com.situ.mall.common.util.Result;
import com.situ.mall.pojo.entity.user.User;
import com.situ.mall.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Gao
 * @since 2024-10-14
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("/login")
    public Result<User> login(@RequestBody User user) {
        //Result<User> result = userService.login(user);
        //return result;

        User loginUser = userService.login(user);
        return Result.ok(loginUser);
    }

    @GetMapping("/selectById/{id}")
    public Result<User> selectById(@PathVariable Long id) {
        User user = userService.getById(id);
        return Result.ok(user);
    }

    @PutMapping("/updateBalance")
    public Result<User> updateBalance(Long userId, BigDecimal balance) {
        userService.updateBalance(userId, balance);
        return Result.ok();
    }

    @PutMapping("/update")
    public Result update(@RequestBody User user) {
        userService.update(user);
        return Result.ok("更新成功");
    }

    @PutMapping("/reCharge")
    public Result reCharge(@RequestBody User user) {
        userService.reCharge(user);
        return Result.ok("充值成功");
    }

}

